<?php


namespace addon\hotel\model;

use think\facade\Cache;
use app\model\BaseModel;

/**
 * 房间类型管理
 * @author Administrator
 *
 */
class RoomType extends BaseModel
{

    //酒店设施
    public $facilities = [
        [
            'title'=>'床',
            'name'=>'bed',
            'icon'=>'addon/hotel/hotel/view/public/img/room_icon/14.png',
            'value'=>''
        ],
        [
            'title'=>'面积',
            'name'=>'area',
            'icon'=>'addon/hotel/hotel/view/public/img/room_icon/15.png',
            'value'=>''
        ],
        [
            'title'=>'楼层',
            'name'=>'floor',
            'icon'=>'addon/hotel/hotel/view/public/img/room_icon/16.png',
            'value'=>''
        ],
        [
            'title'=>'窗户',
            'name'=>'window',
            'icon'=>'addon/hotel/hotel/view/public/img/room_icon/17.png',
            'value'=>'部分无窗'
        ],
        [
            'title'=>'wifi',
            'name'=>'wifi',
            'icon'=>'addon/hotel/hotel/view/public/img/room_icon/18.png',
            'value'=>'免费wifi'
        ],
        [
            'title'=>'有线宽带',
            'name'=>'broadband',
            'icon'=>'addon/hotel/hotel/view/public/img/room_icon/19.png',
            'value'=>'有线宽带免费'
        ],
        [
            'title'=>'禁烟',
            'name'=>'bansmoking',
            'icon'=>'addon/hotel/hotel/view/public/img/room_icon/20.png',
            'value'=>'禁烟'
        ],
        [
            'title'=>'入驻人数',
            'name'=>'occupancy',
            'icon'=>'addon/hotel/hotel/view/public/img/room_icon/21.png',
            'value'=>'2人'
        ],
        [
            'title'=>'早餐',
            'name'=>'breakfast',
            'icon'=>'addon/hotel/hotel/view/public/img/room_icon/22.png',
            'value'=>'无早餐'
        ],
    ];

    /**
     * 添加房间
     * @param array $data
     */
    public function addRoomType($data)
    {
        $ap_id = model('hotel_room_type')->add($data);
        model('hotel_room_type')->update(['baoyu_type_id'=>$ap_id], [['type_id','=',$ap_id]]);
        Cache::tag("hotel_room_type")->clear();
        return $this->success($ap_id);
    }

    /**
     * 修改房间
     * @param array $data
     */
    public function editRoomType($data, $condition)
    {
        $res = model('hotel_room_type')->update($data, $condition);
        Cache::tag("hotel_room_type")->clear();
        return $this->success($res);
    }

    /**
     * 删除房间
     * @param array $condition
     */
    public function deleteRoomType($condition)
    {
        $res = model('hotel_room_type')->delete($condition);
        Cache::tag("hotel_room_type")->clear();
        return $this->success($res);
    }

    /**
     * 获取房间基础信息
     * @param int $ap_id
     * @return multitype:string mixed
     */
    public function getRoomTypeInfo($type_id)
    {
        $cache = Cache::get("room_type_getRoomTypeInfo_" . $type_id);
        if (!empty($cache)) {
            return $this->success($cache);
        }
        $res = model('hotel_room_type')->getInfo([ [ 'type_id', '=', $type_id ] ], '*');
        Cache::tag("hotel_room_type")->set("room_type_getRoomTypeInfo_" . $type_id, $res);
        return $this->success($res);
    }

    /**
     * 获取房间列表
     * @param array $condition
     * @param string $field
     * @param string $order
     * @param string $limit
     */
    public function getRoomTypeList($condition = [], $field = '*', $order = 'type_id desc', $limit = null)
    {
        $data = json_encode([ $condition, $field, $order, $limit ]);
        $cache = Cache::get("room_type_getRoomTypeList_" . $data);
        if (!empty($cache)) {
            return $this->success($cache);
        }
        $list = model('hotel_room_type')->getList($condition, $field, $order, '', '', '', $limit);
        Cache::tag("hotel_room_type")->set("room_type_getRoomTypeList_" . $data, $list);

        return $this->success($list);
    }

    /**
     * 获取房间分页列表
     * @param array $condition
     * @param number $page
     * @param string $page_size
     * @param string $order
     * @param string $field
     */
    public function getRoomTypePageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = 'type_id desc', $field = '*',$alias='a', $join=[])
    {
        $data = json_encode([ $condition, $field, $order, $page, $page_size ]);
        $cache = Cache::get("room_type_getRoomTypePageList_" . $data);
        if (!empty($cache)) {
            return $this->success($cache);
        }

        $list = model('hotel_room_type')->pageList($condition, $field, $order, $page, $page_size, $alias, $join);
        Cache::tag("hotel_room_type")->set("room_type_getRoomTypePageList_" . $data, $list);
        return $this->success($list);
    }

}